package com.cambright.lotusroot
{
	import com.cambright.Enumerator;
	
	import flash.events.EventDispatcher;
	
	public class Module extends EventDispatcher
	{
		public function get asynInitial():Boolean
		{
			return false;
		}
		
		public function get commandMap():CommandMap 
		{
			return null;
		}
		
		public function get mainCommand():Class
		{
			return null;
		}
		
		public function get require():Vector.<Class>
		{
			return null;
		}
		
		private var _initialized:Boolean = false;
		protected function initialize():void {}
		internal function $initialize():void
		{
			_widgetEnumerator.release();
			initialize();
			_initialized = true;
		}
		
		private var _widgetVec:Vector.<Widget> = new Vector.<Widget>();
		
		protected function pushWidget(definition:Class):*
		{
			var key:WidgetKey = new WidgetKey(this);
			var widget:Widget = new definition();
			widget.setKey(key);
			widget.$invoke();
			_widgetVec.push(widget);
			return widget;
		}
		
		private var _widgetEnumerator:Enumerator = new Enumerator(_widgetVec);
		internal function $update():void
		{
			_widgetEnumerator.capture();
			while(_widgetEnumerator.next())
				(_widgetEnumerator.current as Widget).$update();
			_widgetEnumerator.release();
		}
	}
}